"""
员工增删改查的API类
"""
import requests

from common.get_token import get_login_token


class IhrmEmpApi(object):

    # 添加员工
    @classmethod
    def add_emp(cls, token, request_data):
        resp = requests.post(url="http://ihrm-test.itheima.net/api/sys/user",
                             headers={"Authorization": token},
                             json=request_data)

        return resp

    # 修改员工
    @classmethod
    def modify_emp(cls, id, token, request_data):
        resp = requests.put(url="http://ihrm-test.itheima.net/api/sys/user/" + id,
                            headers={"Authorization": token},
                            json=request_data)

        return resp

    # 查询员工
    @classmethod
    def query_emp(cls, id, token):
        resp = requests.get(url="http://ihrm-test.itheima.net/api/sys/user/" + id,
                            headers={"Authorization": token})

        return resp

    # 删除员工
    @classmethod
    def delete_emp(cls, id, token):
        resp = requests.delete(url="http://ihrm-test.itheima.net/api/sys/user/" + id,
                               headers={"Authorization": token})

        return resp


if __name__ == '__main__':
    emp_id = "1524641546572464128"
    token = get_login_token()  # token未来一次测试, 只需要获取一次, 没必要写死

    add_data = {"username": "hzb", "mobile": "13212234553", "workNumber": "123412412412"}
    resp = IhrmEmpApi.add_emp(token, add_data)
    print("添加员工", resp.json())

    modify_data = {"username": "惠主播"}
    resp = IhrmEmpApi.modify_emp(emp_id, token, modify_data)
    print("修改员工", resp.json())

    resp = IhrmEmpApi.query_emp(emp_id, token)
    print("查询员工", resp.json())

    resp = IhrmEmpApi.delete_emp(emp_id, token)
    print("删除员工", resp.json())
